<?php

use yii\db\Schema;
use yii\db\Migration;

class m160329_082254_alter_creative_fields_as_empty_not_null extends Migration
{
    public function up()
    {
        $sql = <<<FINE
update {{%creative}} set title='' where title is null;
update {{%creative}} set txt='' where txt is null;
update {{%creative}} set adomain_list='' where adomain_list is null;
update {{%creative}} set adomain_full='' where adomain_full is null;
update {{%creative}} set landing_page='' where landing_page is null;
update {{%creative}} set click_monitor_url='' where click_monitor_url is null;
update {{%creative}} set show_monitor_url='' where show_monitor_url is null;
FINE;
        $this->execute($sql);

        $this->alterColumn('{{%creative}}', 'title', "varchar(128) not null default '' comment '创意 title '");
        $this->alterColumn('{{%creative}}', 'txt', "varchar(1024) not null default '' comment '创意 content '");
        $this->alterColumn('{{%creative}}', 'adomain_list', "varchar(1024) not null default '' comment '跳转的全域名'");
        $this->alterColumn('{{%creative}}', 'adomain_full', "varchar(1024) not null default '' comment '跳转地址 urls'");
        $this->alterColumn('{{%creative}}', 'landing_page', "varchar(1024) not null default '' comment '目标地址url'");
        $this->alterColumn('{{%creative}}', 'click_monitor_url', "varchar(1024) not null default '' comment '点击监测url'");
        $this->alterColumn('{{%creative}}', 'show_monitor_url', "varchar(1024) not null default '' comment '曝光监测url'");
    }

    public function down()
    {
        return true;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
